var FeedView = Backbone.View.extend({
	events: {
    },
	
	// can we pass in an array of different Views that are tied to the model?
	// then we can hot swap views in and out depending on what page we are on
	initialize: function (options) {
	
		_.bindAll(this, 'addOne', 'onRefresh');
		this.model.bind('add',     this.addOne);
		this.model.bind('refresh', this.onRefresh);
	},

    addOne: function (feedItem) {
        var view = new FeedItemView({model: feedItem });
        $("#dish-feed").append(view.render().el);
    },
	
	onRefresh: function() {
		$("#dish-feed").html("");
		this.model.each(this.addOne);
	},

});


var PhotoCollectionView = Backbone.View.extend({
	events: {
    },
	
	// can we pass in an array of different Views that are tied to the model?
	// then we can hot swap views in and out depending on what page we are on
	initialize: function (options) {
	
		//this.el = $("#dish-thumbs");
		
		_.bindAll(this, 'addOne', 'onRefresh');
		this.model.bind('add',     this.addOne);
		this.model.bind('refresh', this.onRefresh);
	},

    addOne: function (photo) {
        var view = new PhotoView({model: photo });
        $("#dish-thumbs").append(view.render().el);
    },
	
	onRefresh: function() {
		$("#dish-thumbs").html("");
		this.model.each(this.addOne);
	},

});



var DishCollectionView = Backbone.View.extend({
	events: {
    },
	
	// can we pass in an array of different Views that are tied to the model?
	// then we can hot swap views in and out depending on what page we are on
	initialize: function (options) {
		//this.isMapsView = options.isMapsView;
		//this.shouldDisplayNames = options.shouldDisplayNames;
		
		_.bindAll(this, 'addOne', 'onRefresh');
		this.model.bind('add',     this.addOne);
		this.model.bind('refresh', this.onRefresh);
		
		// used to store markers
		this.model.markers = new Array();
		
		// must do this for all other views (tell what element it is attached to)
		//this.el = $(".dish-photo-list");
		
		//this.el2 = $("#dish-names-list");
	
	},

    addOne: function (dish) {
		var num = dish.get("lat") + dish.get("lng");
		if (num in this.model.markers) {
			dish.marker = this.model.markers[num];
		}
		else
		{			
			var image = new google.maps.MarkerImage('/site_media/numeric.png');
			var marker = new google.maps.Marker({
				map: this.map,
				position: new google.maps.LatLng(dish.get("lat"), dish.get("lng")),
				icon: image
			});
			dish.marker = marker;
			this.model.markers[num] = marker
		}
		
        var view = new DishView({model: dish, el: $("#" + dish.id)});
        //$(this.el).append(view.render().el);
		
		//if (this.shouldDisplayNames)
		//{
			//var rankView = new RankView({model: dish, isMapsView: this.isMapsView});
			//$(this.el2).append(rankView.render().el);
		//}
		
		// tags view depends on a dish view being rendered
		//dish.tags.refresh(dish.rawTagList);
    },
	
	onRefresh: function() {
		$(this.el).html("");
		//$(this.el2).html("");
		this.model.each(this.addOne);
	},

});

var ReviewCollectionView = Backbone.View.extend({
	events: {
    },
	
	initialize: function (options) {		
		_.bindAll(this, 'addOne', 'onRefresh');
		this.model.bind('add',     this.addOne);
		this.model.bind('refresh', this.onRefresh);
		
		// must do this for all other views (tell what element it is attached to)
		this.el = $("#reviews_container");
		
		this.quick_review_template = _.template($('#quick_review_template').html());
		
		var quick_review_template = this.quick_review_template;
		$(".post_review_link").click(function () {
			$("#content-insertion-box").html(quick_review_template());
				$(".publish_btn").button().click(function () {
					$(this).fadeOut(3000);
					return false;
				});
				$(".cancel_btn").button().click(function () {
					$(this).fadeOut(3000);
					return false;
				});
			return false;
		});
	},

    addOne: function (review) {
	
        var view = new ReviewView({model: review});
        $(this.el).append(view.render().el);
    },
	
	onRefresh: function() {
		$(this.el).html("");
		this.model.each(this.addOne);
	},

});
